﻿/*-----------------------------------------------------------------------------------------------
// Copyright (C) yangrongfeng 
//
// 文件名：        HomeController.cs
// 文件功能描述：   范例首页控制器
//
// 
// 创建标识：       杨荣峰  2016-04-21
//
// 修改标识：
// 修改描述：
//
// 备注：	
// 				
//-----------------------------------------------------------------------------------------------*/

using HYBY.Task.Service;
using HYBY.Task.Service.IService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Web.Models;

namespace Web.Controllers {

    public class HomeController : BaseWebController {

        private readonly IMatMenuService _service;

        public HomeController(IMatMenuService service) {
            _service = service;

        }

        public ActionResult Index(String searchKey = null) {
            var model = new MatMenuListModel();
            model.PageTitle = "首页";
            model.PageSubTitle = "菜单管理";
            model.ViewList = _service.GetMenus();
            return View(model);
        }

        public ActionResult GetMatMenuList(PageAndSearchInfo search = null) {
            var model = new MatMenuListModel();
            model.PageTitle = "首页";
            model.PageSubTitle = "菜单管理";
            int RecordCount = 0;
            search.PageSize = 10;
            if (search != null) model.ViewList = _service.GetMat_Menus(search,out RecordCount);
            //if (earch)
            ViewBag.RecordCount = RecordCount;
            //model.ViewList = _service.GetMenus();
            return PartialView("_MatMenuList", model);
        }

        public ActionResult Create() {            
            return View();
        }

        [HttpPost]
        public ActionResult Create(MatMenuModel model) {
            return View(model);
        }

        public ActionResult CreateAsynchronous(MatMenuModel model) {
            return Json(new { Succeed = true, Message = "数据保存成功！" });
        }

        public ActionResult BatchCreate(List<MatMenuModel> models) {
            return Json(new { Succeed = true, Message = "数据保存成功！" });
        }

        public ActionResult Edit(int id) {
            return View();
        }

        [HttpPost]
        public ActionResult Edit(MatMenuModel model) {
            return View(model);
        }


        public ActionResult About() {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact() {
            ViewBag.Message = "Your contact page.";
            return View();
        }
    }
}